<template>
  <el-dialog
    title="发送短信验证码"
    :visible.sync="dialogVisible"
    width="350px">
    <div>
      <div align="center">
        <img ref="verfiyImg"
             height="28"
             style="position: relative; top: 10px;"
             :src="verifiyImageUrl"
             @click="reflshVerifyImg">
        <el-input v-model="verifiyValue" placeholder="图片验证码" style="width: 120px"></el-input>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="sendSms">发 送</el-button>
    </div>
  </el-dialog>

</template>

<script>
export default {
  name: "SendSmsDialog",
  data: function () {
    return {
      mobile: '',
      eventType: '',
      verifiyImageUrl: this.ApiDoNameAuth + 'Verify/createImage?eventType=sendSms&deviceId=' + this.GetDeviceID(),
      verifiyValue: '',
      dialogVisible: false,
      callBackFunction: null
    }
  },
  mounted() {
    let $this = this
    $this.bus.$on('SendSmsDialogCallBus', function (mobile, eventType, callBackFunction) {
      $this.dialogVisible = true
      $this.mobile = mobile
      $this.eventType = eventType
      $this.callBackFunction = callBackFunction
      // $this.reflshVerifyImg()
      $this.verifiyImageUrl= $this.ApiDoNameAuth + 'Verify/createImage?eventType=sendSms&deviceId=' + $this.GetDeviceID()+'&v=' + Math.random()
      $this.verifiyValue=''
      $this.$forceUpdate()
    })

  },
  methods: {
    // 发送操作
    sendSms: function () {
      let $this = this
      if ($this.verifiyValue.length < 4) {
        return $this.$message.error("验证码 错误")
      }
      $this.MyRequest($this.ApiDoNameAuth + 'Verify/sendSms', {
        eventType: $this.eventType,
        mobile: $this.mobile,
        imageVerifyCode: $this.verifiyValue,
      }, function () {
        $this.dialogVisible=false
        $this.isLoading = false
        $this.callBackFunction()
      }, function (msg) {
        $this.isLoading = false
        $this.$message.error(msg)
        $this.reflshVerifyImg()
      })
    },


    // 刷新-验证码
    reflshVerifyImg: function () {
      this.$refs.verfiyImg.src = this.verifiyImageUrl + '&v=' + Math.random()
      this.verifiyValue = ''
    },
  }
}
</script>

<style scoped>

</style>
